Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compat: pthread.h shim for FreeRTOS #978

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

projectgoav
Copy link

As discussed in #960.

Assumes that anyone wishing to build for FreeRTOS will define FREERTOS and ensure that the FreeRTOS headers are added to the include path at FreeRTOS/___


pthread_once

I wasn't sure if this has to be thread-safe. Can easily adjust this if required.

Syslog Support

I had to adjust the compat/syslog.h slighty to account for more than just Windows not providing syslog. Please let me know if there is a better/cleaner/more LibreSSLy way of doing things like this.

I liked making sure of the already defined NO_SYSLOG which is used as part of crypto/compat/r_syslog.c hence why this was picked.

Sockets / Networking

We currently use the LWIP networking stack. My plan was to submit another PR with a compatibility shim for that. As a result, I don't know the status of building for the built-in FreeRTOS stack. It's my understanding it follows the standard socket API so might just work (TM)...

Copy link
Contributor

@botovq botovq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a first pass over your diff and it looks pretty good. Most of my comments are very nitpicky and stylistic. The main points:

  • Please make the libressl_ prefixing completely straightforward, so we change things this using sed, as far as possible.
  • The pthread API is special in that it returns an errno value, not -1 (there's also a bug in the windows shim).
  • I am fine with using the NO_SYSLOG logic, but it needs fixing for WIN32 on the autotools level.

include/compat/freertosthreadcompat.h Outdated Show resolved Hide resolved
include/compat/freertosthreadcompat.h Outdated Show resolved Hide resolved
include/compat/freertosthreadcompat.h Show resolved Hide resolved
include/compat/freertosthreadcompat.h Outdated Show resolved Hide resolved
include/compat/freertosthreadcompat.h Outdated Show resolved Hide resolved
Comment on lines 113 to 123
xSemaphoreHandle x = mutex->handle;
if (x) {
if ( xSemaphoreGive(x) == pdTRUE ) {
return 0;
}
else {
return -1;
}
}

return 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
xSemaphoreHandle x = mutex->handle;
if (x) {
if ( xSemaphoreGive(x) == pdTRUE ) {
return 0;
}
else {
return -1;
}
}
return 0;
if (mutex->handle == NULL)
return 0;
if (xSemaphoreGive(mutex->handle) == pdTRUE)
return 0;
return -1;

Copy link
Author

@projectgoav projectgoav Dec 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In mutex_lock we:

  • Return -1 if the mutex handle is NULL, here we return 0. Should we be consistent here and return -1 as well?
  • We compare != pdTRUE and final return is the happy path. Here, we compare == pdTRUE and the final return is a non-happy path. Should we be consistent and != pdTRUE with happy path the final return?

include/compat/freertosthreadcompat.h Outdated Show resolved Hide resolved
include/compat/syslog.h Outdated Show resolved Hide resolved
@@ -14,7 +18,7 @@

#include <stdarg.h>

#ifdef _WIN32
#ifdef NO_SYSLOG
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine if we fix autotools.

pthread_once(pthread_once_t *once, void (*cb) (void))
{
if (!once->is_initialized) {
return -1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all return -1 should actually be an errno, such as EINVAL. This seems also incorrect in the windows pthread shim. I have not corrected that in my suggestions below.

@busterb
Copy link
Contributor

busterb commented May 31, 2024

Hi @projectgoav do you have build / test instructions for this branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants